package edu.xhu.adapters;

import java.util.ArrayList;

import com.bean.ScoreBean;

import edu.xhu.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class EduSystemGradesAdapter extends BaseAdapter{

	private ArrayList<ScoreBean> mScoreList;
	private LayoutInflater inflater;
	
	public EduSystemGradesAdapter(Context context, ArrayList<ScoreBean> mScoreList){
		this.inflater = LayoutInflater.from(context);
		this.mScoreList = mScoreList;
	}
	
	public int getCount() {
		if (null == mScoreList)
			return 0;
		return mScoreList.size();
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (null == convertView){
			viewHolder			= new ViewHolder();
			convertView			= inflater.inflate(R.layout.edusystem_grades_item, null);
			viewHolder.cName	= (TextView) convertView.findViewById(R.id.textview_cname);
//			viewHolder.term		= (TextView) convertView.findViewById(R.id.textview_term);
			viewHolder.cCode	= (TextView) convertView.findViewById(R.id.textview_coursecode);
//			viewHolder.year		= (TextView) convertView.findViewById(R.id.textview_year);
			viewHolder.nature	= (TextView) convertView.findViewById(R.id.textview_coursenature);
			viewHolder.credit	= (TextView) convertView.findViewById(R.id.textview_credit);
			viewHolder.gradePoint = (TextView) convertView.findViewById(R.id.textview_gradepoint);
			viewHolder.grades	= (TextView) convertView.findViewById(R.id.textview_grades);
			viewHolder.reGrades	= (TextView) convertView.findViewById(R.id.textview_recode);
			viewHolder.college	= (TextView) convertView.findViewById(R.id.textview_colleges);
			
			convertView.setTag(viewHolder);
		}else {
			viewHolder			= (ViewHolder) convertView.getTag();
		}
		
		ScoreBean bean 			= mScoreList.get(position);
		
		viewHolder.cName.setText("课程名称：" + bean.courseName);
//		viewHolder.term.setText("学期：" + bean.)
		viewHolder.cCode.setText("课程代码：" + bean.courseCode);
		viewHolder.nature.setText("课程性质：" + bean.courseProperties);
		viewHolder.credit.setText("学         分：" + bean.coursecredit);
		viewHolder.gradePoint.setText("绩         点：" + bean.gradeDot);
		viewHolder.grades.setText("成         绩：" + bean.grade);
		viewHolder.reGrades.setText("重修成绩：" + bean.replyGrade);
		viewHolder.college.setText("开课学院：" + bean.college);
		
		if (getCount() == 1){
			convertView.setBackgroundResource(R.drawable.full_selector);
		}else {
			if (0 == position){
				convertView.setBackgroundResource(R.drawable.top_selector);
			}else if (getCount()-1 == position){
				convertView.setBackgroundResource(R.drawable.bottom_selector);
			}else {
				convertView.setBackgroundResource(R.drawable.middle_selector);
			}
		}
		
		return convertView;
	}

	class ViewHolder{
		public TextView cName;					//课程名称					
//		public TextView term;					//学期					
		public TextView cCode;					//课程代码				
//		public TextView year;					//学年				
		public TextView nature;					//课程性质				
		public TextView credit;					//学分				
		public TextView gradePoint;				//绩点
		public TextView grades;					//成绩
		public TextView reGrades;				//重修成绩
		public TextView college;				//学院
	}
}
